#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 15;

int n, m;
int head[N];
ll g[N][N];
void add(int u, int v, ll w) { g[u][v] = w; }
ll ans = 1ll << 60;
int vis[N];
void dfs(int u, ll w) {
  if (u == n) ans = min(ans, w);
  vis[u] = 1;
  rep(v, 1, n) {
    if (!vis[v] && g[u][v]) dfs(v, w ^ g[u][v]);
  }
  vis[u] = 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
    if (!w) {
      cout << 0;
      return 0;
    }
  }
  dfs(1, 0);
  cout << ans;
  return 0;
}